﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

/// <summary>
/// 对cookie的操作
/// </summary>
public static class CommonHelper
{
    private const string pwSalt = "AlrySqloPe2Mh784QQwG6jRAfkdPpDa90JOi";//密码加密随机串

    /// <summary>
    /// 密码异或加密， 第一次异或加密， 第二次异或解密
    /// </summary>
    /// <param name="password">密码</param>
    /// <param name="model">异或字符串</param>
    /// <returns></returns>
    public static string XOR(string password)
    {
        char[] tempPsw = password.ToCharArray();
        char[] modelC = pwSalt.ToCharArray();
        StringBuilder secretPsw = new StringBuilder();
        for (int i = 0; i < tempPsw.Length; i++)
        {
            char c = (char)(tempPsw[i] ^ modelC[i]);
            secretPsw.Append(c);
        }
        return secretPsw.ToString();
    }


    /// <summary>
    /// 生成随机字符串
    /// <returns>随机字符串</returns>
    public static string RandomString()
    {
        string temp = "0,1,2,3,4,5,6,7,8,9,a,,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        string[] StringTemp = temp.Split(',');//分割字符串
        string randomString = "";//要返回的随机字符串
        for (int i = 0; i < 10; i++)
        {
            Random random = new Random();
            int n = random.Next(0, 62);//产生0~61的随机数
            randomString += StringTemp[n];
        }
        return randomString;
    }
}
